| Conditions | 1 |
| Paths | 1 |
| Total Lines | 70 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** |
||
| 18 | function dark(state, format, visibility, upgrade, data, util) { |
||
| 19 | let ct = this; |
||
| 20 | ct.state = state; |
||
| 21 | ct.data = data; |
||
| 22 | ct.util = util; |
||
| 23 | ct.format = format; |
||
| 24 | |||
| 25 | ct.darkProduction = function() { |
||
| 26 | let production = 0; |
||
| 27 | for (let element in data.elements) { |
||
| 28 | let exotic = data.elements[element].exotic; |
||
| 29 | if (!state.player.resources[exotic].unlocked) { |
||
| 30 | continue; |
||
| 31 | } |
||
| 32 | production += Math.floor(Math.max(0, Math.log(state.player.resources[exotic].number))); |
||
| 33 | } |
||
| 34 | |||
| 35 | return production; |
||
| 36 | }; |
||
| 37 | |||
| 38 | ct.darkPrestige = function() { |
||
| 39 | let resources = state.player.resources; |
||
| 40 | let production = ct.darkProduction(); |
||
| 41 | |||
| 42 | resources.dark_matter.number += production; |
||
| 43 | resources.dark_matter.unlocked = true; |
||
| 44 | |||
| 45 | for(let key in data.elements){ |
||
| 46 | let element = data.elements[key]; |
||
| 47 | state.player.resources[element.exotic].number = 0; |
||
| 48 | if(!state.player.exotic_upgrades[key]){ |
||
| 49 | continue; |
||
| 50 | } |
||
| 51 | for(let up in data.exotic_upgrades){ |
||
| 52 | state.player.exotic_upgrades[key][up] = false; |
||
| 53 | } |
||
| 54 | } |
||
| 55 | for(let slot of state.player.element_slots){ |
||
| 56 | if(!slot){ |
||
| 57 | continue; |
||
| 58 | } |
||
| 59 | upgrade.resetElement(state.player, slot.element); |
||
| 60 | } |
||
| 61 | |||
| 62 | for(let i in state.player.element_slots){ |
||
| 63 | state.player.element_slots[i] = null; |
||
| 64 | } |
||
| 65 | }; |
||
| 66 | |||
| 67 | ct.buyDarkUpgrade = function(name) { |
||
| 68 | let upgrades = state.player.dark_upgrades; |
||
| 69 | let price = data.dark_upgrades[name].price; |
||
| 70 | let currency = 'dark_matter'; |
||
| 71 | upgrade.buyUpgrade(state.player, |
||
| 72 | upgrades, |
||
| 73 | data.dark_upgrades[name], |
||
| 74 | name, |
||
| 75 | price, |
||
| 76 | currency); |
||
| 77 | }; |
||
| 78 | |||
| 79 | ct.visibleDarkUpgrades = function() { |
||
| 80 | return visibility.visible(data.dark_upgrades, isDarkUpgradeVisible, 0); |
||
| 81 | }; |
||
| 82 | |||
| 83 | // here we receive not the name of the element, but the index in the element_slots |
||
| 84 | function isDarkUpgradeVisible(name, index) { |
||
| 85 | return visibility.isUpgradeVisible(name, index, data.dark_upgrades[name]); |
||
| 86 | } |
||
| 87 | } |
||
| 88 |